package cn.edu.mju.property.service.impl;

import cn.edu.mju.property.dao.RepairDao;
import cn.edu.mju.property.dao.impl.RepairDaoImpl;
import cn.edu.mju.property.entity.PageBean;
import cn.edu.mju.property.entity.Repair;
import cn.edu.mju.property.entity.User;
import cn.edu.mju.property.service.RepairService;

import java.util.List;

public class RepairServiceImpl implements RepairService {

    private RepairDao dao = new RepairDaoImpl();


    @Override
    public boolean addRepair(Repair repair) {
        return dao.addRepair(repair);
    }

    @Override
    public boolean delRepair() {
        return false;
    }

    @Override
    public boolean updateRepair(Repair repair) {
        return false;
    }

    @Override
    public PageBean<Repair> findByPage(String _currentPage, String _rows) {

        int currentPage = Integer.parseInt(_currentPage) ;
        int rows = Integer.parseInt(_rows) ;

        PageBean<Repair> pb = new PageBean<Repair>();
        pb.setCurrentPage(currentPage);
        pb.setRows(rows);

        //总记录数
        int totalCount = dao.findTotalCount();
        pb.setTotalCount(totalCount);

        //开始值
        int start = (currentPage - 1) * rows;
        List<Repair> list = dao.findByPage(start,rows);
        pb.setList(list);

        int totalPage = totalCount % rows == 0 ? (totalCount/rows) : (totalCount/rows) + 1;
        pb.setTotalPage(totalPage);

        return pb;
    }
}
